<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(tlck) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://192.168.0.184/log/test/$dateTime.'a'", "r");
//$handle = fopen("http://192.168.0.184/log/tlck/log", "r");
$handle = fopen("/var/www/log/tlck/log", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);
    $id = $arr2["equipUsedInfos"];
    $arr3 = json_decode($id, true);
  
    $id2 = $arr2["task"];
    $id3 = $arr2["lastUi"];
    $id4 = $arr2["dayUI1Count"];
    $id5 = $arr2["dayUI2Count"];
    $id6 = $arr2["dayUI3Count"];
    $id7 = $arr2["dayUI4Count"];
    $id8 = $arr2["dayUI5Count"];
    $id9 = $arr2["dayUI6Count"];
    $id10 = $arr2["fightNum"];
    $id11 = $arr2["DailyTCNum"];
    $id12 = $arr2["dayPlayShortTime"];
    $id13 = $arr2["dayPlayLongTime"];
    $id14 = $arr2["dayUsedMoney"];
    $id15 = $arr2["p1lastLevel"];
    $id16 = $arr2["p2lastLevel"];
    $id17 = $arr2["p3lastLevel"];
    $id18 = $arr2["DailyTCTimes"];
    $id19 = $arr2["succNum"];

    $id20 = $arr2["nowMoney"];
    $id21 = $arr2["dayTotalTime"];
    $id22 = $arr2["dayPlayAvgTime"];

    $id23 = $arr2["dayGetMoney"];
    $id24 = $arr2["totalTime"];
    $id25 = $arr2["totalMoney"];
    $id26 = $arr2["dayPlayTime"];
    $id27 = $arr2["lastLevel"];


    $id28 = $arr3["A1"];
    $id29 = $arr3["A2"];
    $id30 = $arr3["A3"];
    $id31 = $arr3["A4"];
    $id32 = $arr3["A5"];
    $id33 = $arr3["A6"];
    $id34 = $arr3["A7"];
    $id35 = $arr3["A8"];
    $id36 = $arr3["A9"];
    $id37 = $arr3["A10"];
    $id38 = $arr3["A11"];
    $id39 = $arr3["A12"];
    $id40 = $arr3["A13"];
    $id41 = $arr3["A14"];
  

    $id42 = $arr3["B1"];
    $id43 = $arr3["B2"];
    $id44 = $arr3["B3"];
    $id45 = $arr3["B4"];
    $id46 = $arr3["B5"];
    $id47 = $arr3["B6"];
    $id48 = $arr3["B7"];
    $id49 = $arr3["B8"];
    $id50 = $arr3["B9"];
    $id51 = $arr3["B10"];

    $id52 = $arr3["C1"];
    $id53 = $arr3["C2"];
    $id54 = $arr3["C3"];
    $id55 = $arr3["C4"];
    $id56 = $arr3["C5"];
    $id57 = $arr3["C6"];
    $id58 = $arr3["C7"];
    $id59 = $arr3["C8"];  
    $id60 = $arr3["C9"];
    $id61 = $arr3["C10"];

    $id62 = $arr3["D1"];
    $id63 = $arr3["D2"];
    $id64 = $arr3["D3"];
    $id65 = $arr3["D4"];
    $id66 = $arr3["D5"];
    $id67 = $arr3["D6"];
    $id68 = $arr3["D7"];
    $id69 = $arr3["D8"];  
    $id70 = $arr3["D9"];
    $id71 = $arr3["D10"];

    $id72 = $arr3["E1"];
    $id73 = $arr3["E2"];
    $id74 = $arr3["E3"];
    $id75 = $arr3["E4"];
    $id76 = $arr3["E5"];
    $id77 = $arr3["E6"];
    $id78 = $arr3["E7"];
    $id79 = $arr3["E8"];  
    $id80 = $arr3["E9"];
    $id81 = $arr3["E10"];

    $id82 = $arr3["F1"];
    $id83 = $arr3["F2"];
    $id84 = $arr3["F3"];
    $id85 = $arr3["F4"];
    $id86 = $arr3["F5"];
    $id87 = $arr3["F6"];
    $id88 = $arr3["F7"];
    $id89 = $arr3["F8"];  
    $id90 = $arr3["F9"];
    $id91 = $arr3["F10"];

    $id182 = $arr3["G1"];
    $id183 = $arr3["G2"];
    $id184 = $arr3["G3"];
    $id185 = $arr3["G4"];
    $id186 = $arr3["G5"];
    $id187 = $arr3["G6"];
    $id188 = $arr3["G7"];
    $id189 = $arr3["G8"];  
    $id190 = $arr3["G9"];
    $id191 = $arr3["G10"];

    $id282 = $arr3["H1"];
    $id283 = $arr3["H2"];
    $id284 = $arr3["H3"];
    $id285 = $arr3["H4"];
    $id286 = $arr3["H5"];
    $id287 = $arr3["H6"];
    $id288 = $arr3["H7"];
    $id289 = $arr3["H8"];  
    $id290 = $arr3["H9"];
    $id291 = $arr3["H10"];

    $id101 = $arr2["firstlogindata"];
    $id102 = $arr2["jailbreak"];
    $id103 = $arr2["lastUi"]; 
    $id104 = $arr2["nowMoney"];
    $id105 = $arr2["totalMoney"];
    $id106 = $arr2["totalTime"];
    $id107 = $arr2["deviceid"];
    $id108 = $arr["gamename"];
    $id109 = $arr["createdate"];
    $id110 = $arr2["createdate"];

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
    	
        $task = $id2;
        $lastUi = $id3;
        $dayUI1Count = $id4;
        $dayUI2Count = $id5;
        $dayUI3Count = $id6;
        $dayUI4Count = $id7;
        $dayUI5Count = $id8;
        $dayUI6Count = $id9;
        $fightNum = $id10;
        $DailyTCNum = $id11;
        $dayPlayShortTime = $id12;
        $dayPlayLongTime = $id13;

        $dayUsedMoney = $id14;
        $p1lastLevel = $id15;
        $p2lastLevel = $id16;
        $p3lastLevel = $id17;
        $DailyTCTimes = $id18;
        $succNum = $id19;

        $nowMoney = $id20;
        $dayTotalTime = $id21;
        $dayPlayAvgTime = $id22;

        $dayGetMoney = $id23;

        $totalTime = $id24;
        $totalMoney = $id25;
        $dayPlayTime = $id26 ;
        $lastLevel = $id27;


        $A1 = $id28;
        $A2 = $id29;
        $A3 = $id30 ;
        $A4 = $id31;
        $A5 =  $id32;
        $A6 = $id33;
        $A7 = $id34;
        $A8 = $id35; 
        $A9 = $id36;
        $A10 = $id37;
        $A11 = $id38 ;
        $A12 = $id39;
        $A13 = $id40;
        $A14 = $id41;

        $B1 =  $id42;
        $B2 =  $id43; 
        $B3 = $id44;
        $B4 =  $id45;
        $B5 = $id46;
        $B6 = $id47;
        $B7 = $id48;

        $B8 = $id49;
        $B9 = $id50;
        $B10 = $id51;
        $C1 = $id52;
        $C2 =  $id53;
        $C3 =  $id54;
        $C4 =  $id55;

        $C5 = $id56;
        $C6 = $id57;
        $C7 = $id58;
        $C8 = $id59; 
        $C9 = $id60;
        $C10 =$id61;

        $D1 = $id62;
        $D2 = $id63;
        $D3 = $id64;
        $D4 = $id65;
        $D5 = $id66;
        $D6 = $id67;
        $D7 = $id68;
        $D8 = $id69;
        $D9 = $id70;
        $D10 = $id71;

        $E1 = $id72;
        $E2 =  $id73;
        $E3 =  $id74;
        $E4 = $id75;
        $E5 = $id76;
        $E6 = $id77;
        $E7 = $id78;
        $E8 = $id79;
        $E9 = $id80;
        $E10 = $id81;

        $F1 = $id82;
        $F2 =  $id83;
        $F3 =  $id84;
        $F4 = $id85;
        $F5 = $id86;
        $F6 = $id87;
        $F7 = $id88;
        $F8 = $id89;
        $F9 = $id90;
        $F10 = $id91;

        $G1 = $id182;
        $G2 =  $id183;
        $G3 =  $id184;
        $G4 = $id185;
        $G5 = $id186;
        $G6 = $id187;
        $G7 = $id188;
        $G8 = $id189;
        $G9 = $id190;
        $G10 = $id191;

        $H1 = $id282;
        $H2 =  $id283;
        $H3 =  $id284;
        $H4 = $id285;
        $H5 = $id286;
        $H6 = $id287;
        $H7 = $id288;
        $H8 = $id289;
        $H9 = $id290;
        $H10 = $id291;

        $firstlogindata = $id101;
        $jailbreak = $id102;
        $lastUi =  $id103;
        $nowMoney =  $id104;
        $totalMoney = $id105;
        $totalTime = $id106;
        $deviceid = $id107;
        $gamename = $id108;
        $createdate = $id109;
        //DataTime
        $dataTime = $id110;

   

        mysql_query("INSERT INTO tlck_query ( task,
        lastUi,
        dayUI1Count,
        dayUI2Count,
        dayUI3Count,
        dayUI4Count,
        dayUI5Count,
        dayUI6Count,
        fightNum,
        DailyTCNum,
        dayPlayShortTime,
        dayPlayLongTime,
        dayUsedMoney,
        p1lastLevel,
        p2lastLevel,
        p3lastLevel,
        DailyTCTimes,
        succNum,
        nowMoney,
        dayTotalTime,
        firstlogindata,
        firstlogin,
        dayPlayAvgTime,
        dayGetMoney,
        totalTime,
        totalMoney,
        jailbreak,
        dayPlayTime,
        lastLevel,
        equipUsedInfos,
        A1,
        A2,
        A3,
        A4,
        A5,
        A6,
        A7,
        A8,
        A9,
        A10,
        A11,
        A12,
        A13,
        A14,
        B1,
        B2,
        B3,
        B4,
        B5,
        B6,
        B7,
        B8,
        B9,
        B10,
        C1,
        C2,
        C3,
        C4,
        C5,
        C6,
        C7,
        C8,
        C9,
        C10,
        D1,
        D2,
        D3,
        D4,
        D5,
        D6,
        D7,
        D8,
        D9,
        D10,
        E1,
        E2,
        E3,
        E4,
        E5,
        E6,
        E7,
        E8,
        E9,
        E10,
        F1,
        F2,
        F3,
        F4,
        F5,
        F6,
        F7,
        F8,
        F9,
        F10,
        G1,
        G2,
        G3,
        G4,
        G5,
        G6,
        G7,
        G8,
        G9,
        G10,
        H1,
        H2,
        H3,
        H4,
        H5,
        H6,
        H7,
        H8,
        H9,
        H10,
        deviceid,
        gamename,
        createdate,
        date,dataTime) 
                    VALUES('task',
        '$lastUi',
        '$dayUI1Count',
        '$dayUI2Count',
        '$dayUI3Count',
        '$dayUI4Count',
        '$dayUI5Count',
        '$dayUI6Count',
        '$fightNum',
        '$DailyTCNum',
        '$dayPlayShortTime',
        '$dayPlayLongTime',
        '$dayUsedMoney',
        '$p1lastLevel',
        '$p2lastLevel',
        '$p3lastLevel',
        '$DailyTCTimes',
        '$succNum',
        '$nowMoney',
        '$dayTotalTime',
        '$firstlogindata',
        '$firstlogindata',
        '$dayPlayAvgTime',
        '$dayGetMoney',
        '$totalTime',
        '$totalMoney',
        '$jailbreak',
        '$dayPlayTime',
        '$lastLevel',
        '$equipUsedInfos',
        '$A1',
        '$A2',
        '$A3',
        '$A4',
        '$A5',
        '$A6',
        '$A7',
        '$A8',
        '$A9',
        '$A10',
        '$A11',
        '$A12',
        '$A13',
        '$A14',
        '$B1',
        '$B2',
        '$B3',
        '$B4',
        '$B5',
        '$B6',
        '$B7',
        '$B8',
        '$B9',
        '$B10',
        '$C1',
        '$C2',
        '$C3',
        '$C4',
        '$C5',
        '$C6',
        '$C7',
        '$C8',
        '$C9',
        '$C10',
        '$D1',
        '$D2',
        '$D3',
        '$D4',
        '$D5',
        '$D6',
        '$D7',
        '$D8',
        '$D9',
        '$D10',
        '$E1',
        '$E2',
        '$E3',
        '$E4',
        '$E5',
        '$E6',
        '$E7',
        '$E8',
        '$E9',
        '$E10',
        '$F1',
        '$F2',
        '$F3',
        '$F4',
        '$F5',
        '$F6',
        '$F7',
        '$F8',
        '$F9',
        '$F10',
        '$G1',
        '$G2',
        '$G3',
        '$G4',
        '$G5',
        '$G6',
        '$G7',
        '$G8',
        '$G9',
        '$G10',
        '$H1',
        '$H2',
        '$H3',
        '$H4',
        '$H5',
        '$H6',
        '$H7',
        '$H8',
        '$H9',
        '$H10',
        '$deviceid',
        '$gamename',
        '$createdate',
        '$createdate','$dataTime')") or die(mysql_error());
    }
}
fclose($handle);

print "Import successful!<br>";

?>
